/*******************************************************************************
 * Copyright (C) 2016, Huada Semiconductor Co., Ltd. All rights reserved.
 *
 * This software is owned and published by:
 * Huada Semiconductor Co., Ltd. ("HDSC").
 *
 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
 *
 * This software contains source code for use with HDSC
 * components. This software is licensed by HDSC to be adapted only
 * for use in systems utilizing HDSC components. HDSC shall not be
 * responsible for misuse or illegal use of this software for devices not
 * supported herein. HDSC is providing this software "AS IS" and will
 * not be responsible for issues arising from incorrect user implementation
 * of the software.
 *
 * Disclaimer:
 * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
 * REGARDING THE SOFTWARE (INCLUDING ANY ACCOMPANYING WRITTEN MATERIALS),
 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
 * WARRANTY OF NONINFRINGEMENT.
 * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
 * SAVINGS OR PROFITS,
 * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
 * FROM, THE SOFTWARE.
 *
 * This software may be replicated in part or whole for the licensed use,
 * with the restriction that this Disclaimer and Copyright notice must be
 * included with each copy of this software, whether used in part or whole,
 * at all times.
 */
/******************************************************************************/
/** \file basic.h
 **
 **
 ******************************************************************************/
#ifndef __BASIC_H__
#define __BASIC_H__

/*******************************************************************************
 * Include files
 ******************************************************************************/
#include "ddl.h"

/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif

/*******************************************************************************
 * Global type definitions ('typedef')
 ******************************************************************************/
/**
 *******************************************************************************
 ** \brief Packet status enumeration
 ******************************************************************************/
/**
 *******************************************************************************
 ** \brief Packet status enumeration
 ******************************************************************************/

/**
 *******************************************************************************
 ** \brief Packet command enumeration
 ******************************************************************************/
/**
 *******************************************************************************
 ** \brief Packet command type enumeration
 ******************************************************************************/

/*******************************************************************************
 * Global pre-processor symbols/macros ('#define')
 ******************************************************************************/
/* Flash相关宏定义 */
#define FLASH_BASE_ADDRESS              0x00000000ul
#define FLASH_SECTOR_SIZE               0x200ul                             //一个sector的尺寸
#define FLASH_SIZE                      (36u * FLASH_SECTOR_SIZE)          //flash尺寸
/* RAM相关宏定义 */
#define SRAM_BASE                       ((uint32_t)0x20000000)              //RAM基地址
#define RAM_SIZE                        0x4000ul                            //RAM尺寸
/* BootLoader flash相关宏定义 */
#define BOOT_SIZE                       (8 * FLASH_SECTOR_SIZE)                     //BootLoader flash尺寸
#define BOOT_PARA_ADDRESS               (FLASH_BASE_ADDRESS + BOOT_SIZE - 0x100u)   //BootLoader para存储地址
/* APP flash相关宏定义 */
#define APP_FLAG                        ((uint32_t)0x67890123)                      //从BootLoader para区读到此值，表示APP需要更新
#define APP_ADDRESS                     (FLASH_BASE_ADDRESS + BOOT_SIZE)            //APP程序存储基地址


#define COMM_IRQ_HANDLER                 LPUART0_IRQHandler
//#define TIMEBASE_IRQ_HANDLER             GTIM_BTIM3_4_5_IRQHandler
#define TIMEBASE_IRQ_IS_TRIGGER          (0x01u == BTIM3->IFR_f.UI)
#define TIMEBASE_IRQ_CONDITION_CLEAR     (BTIM3->ICR_f.UI = 0u)

/*******************************************************************************
 * Global variable definitions ('extern')
 ******************************************************************************/

/*******************************************************************************
  Global function prototypes (definition in C source)
 ******************************************************************************/
void PreiModule_Init(void);
void PreiModule_DeInit(void);
void UARTModeSendDataPoll(uint8_t *u8TxBuff, uint16_t u16Length);
uint16_t Cal_CRC16(const uint8_t* pu8Data, uint32_t u32Len);
en_result_t Flash_EraseSector(uint32_t u32Addr);
en_result_t Flash_WriteBytes(uint32_t u32Addr, const uint8_t *pu8WriteBuff, uint32_t u32ByteLength);
void Flash_ReadBytes(uint32_t u32Addr, uint8_t *pu8ReadBuff, uint32_t u32ByteLength);


#ifdef __cplusplus
}
#endif

#endif /* __BASIC_H__ */

/*******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/
